package com.iweb.controller;

import com.iweb.pojo.Notice;
import com.iweb.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("notice")
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    @RequestMapping(value = "index" ,method = RequestMethod.GET)
    public String setNotice(){
        return "admin/notice/index";
    }

    @RequestMapping(value = "addNotice" ,method = RequestMethod.POST)
    public String setNotice(HttpServletRequest req, Notice notice){
        String adminUserID = req.getSession().getAttribute("userID").toString();
        notice.setUserID(adminUserID);
        noticeService.insert(notice);
        return "admin/success";
    }

    @RequestMapping(value = "queryNotice" ,method = RequestMethod.GET)
    public String queryNotice(HttpServletRequest req){
        List list = noticeService.selectList();
        req.setAttribute("list",list);
        return "user/notice/index";
    }
}
